package zut.cs.liziflower.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import zut.cs.liziflower.entity.Cart;
import zut.cs.liziflower.entity.Flower;
import zut.cs.liziflower.mapper.CartMapper;
import zut.cs.liziflower.service.ICartService;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author xuwenke
 * @since 2022-05-19
 */
@Service
@Transactional
public class CartServiceImpl extends ServiceImpl<CartMapper, Cart> implements ICartService {

    @Resource
    private CartMapper cartMapper;

    @Override
    public Cart getByUseridAndFlowerid(Integer userid, Integer flowerid) {
        QueryWrapper<Cart> wrapper = new QueryWrapper<>();
        wrapper.eq("userid", userid)
                .and(q -> q.eq("flowerid", flowerid));
        Cart cart = cartMapper.selectOne(wrapper);
        return cart;
    }

    @Override
    public List<Flower> getCart(Integer userid) {
        List<Flower> list = cartMapper.getCart(userid);
        return list;
    }

    @Override
    public List<Flower> getPage(Integer userid, Integer page, Integer size) {
        return cartMapper.getPage(userid,page,size);
    }

    @Override
    public int changeNumber(Integer userid, Integer flowerid, Integer number) {
        return cartMapper.changeNumber(userid,flowerid,number);
    }
}
